package com.ruoyi.personnel.salary.tax.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.tax.domain.TaxDomain;
import com.ruoyi.personnel.salary.tax.domain.TaxDto;
import com.ruoyi.personnel.salary.tax.service.ITaxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工资所得税
 * 视图层
 */
@RestController
@RequestMapping("/salary/tax")
@Api(value = "工资所得税模块", tags = "工资所得税接口")
public class TaxController extends BaseController {
    @Autowired
    private ITaxService taxService;

    /**
     * 获取工资所得税列表
     * @return
     */
    @ApiOperation(value = "获取工资所得税列表",notes = "查询所有工资所得税信息")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<TaxDto> taxList = taxService.selectIncomeTaxList();
        return getDataTable(taxList);
    }

    /**
     * 新增工资所得税
     *
     * @param tax
     * @return
     */
    @ApiOperation(value = "新增工资所得税记录", notes = "新增工资所得税信息")
    @ApiImplicitParam(name = "tax", value = "新增工资所得税", dataType = "TaxDomain")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TaxDomain tax) {
        return toAjax(taxService.insertIncomeTax(tax));
    }

    /**
     * 修改工资所得税
     *
     * @param tax
     * @return
     */
    @ApiOperation(value = "修改工资所得税", notes = "修改工资所得税")
    @ApiImplicitParam(name = "tax", value = "修改工资所得税(可修改参数：minimumValue、maxValue、taxRate、remark)", dataType = "TaxDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TaxDomain tax) {
        return toAjax(taxService.updateIncomeTax(tax));
    }

    /**
     * 删除工资所得税
     * 仅修改删除标志位
     *
     * @param tax
     * @return
     */
    @ApiOperation(value = "删除工资所得税", notes = "删除工资所得税,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody TaxDomain tax) {
        return toAjax(taxService.updateIncomeTaxDeleteFlag(tax));
    }

    @ApiOperation(value = "读取计时工资", notes = "读取计时工资")
    @GetMapping("/{price}")
    public AjaxResult calculateIncomeTax(@PathVariable Double price) {
        Map<String, Double> map = new HashMap<>();
        Double incomeTax = taxService.calculateIncomeTax(price);
        map.put("incomeTax", incomeTax);
        return AjaxResult.success("查询成功", map);
    }
}
